/**
 * 
 */
package com.music.service.playlists.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.music.service.playlists.beans.Playlist;
import com.music.service.playlists.constants.PlaylistState;

/**
 * @author asanthan
 * Note: This is common mapper. This should be configurable in such a way that it receives what are all
 * the column names to retrieve.
 */
public class PlaylistMapper implements RowMapper {

	/* (non-Javadoc)
	 * @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
	 */
	public Object mapRow(ResultSet pResultSet, int pArg1) throws SQLException {
		Playlist playlist = new Playlist();
		playlist.setPlaylistId(pResultSet.getLong("PLAYLIST_ID"));
		playlist.setOwnerId(pResultSet.getLong("CREATED_MEMBER_ID"));
		playlist.setPlaylistName(pResultSet.getString("PLAYLIST_NAME"));
		playlist.setCreationDate(pResultSet.getDate("CREATION_DATE"));
		playlist.setLastUpdateDate(pResultSet.getDate("LAST_UPDATE_DATE"));
		playlist.setLastAccessedDate(pResultSet.getDate("LAST_ACCESSED_DATE"));
		playlist.setLastAddedSongId(pResultSet.getLong("LAST_ADDED_SONG_ID"));
		playlist.setPlaylistState(PlaylistState.getPlaylistState(pResultSet.getString("state")));
		playlist.setRepeat(pResultSet.getBoolean("REPEAT_ALL"));
		playlist.setShuffle(pResultSet.getBoolean("SHUFFLE"));
		return playlist;
	}

}
